package com.jy.adscm.core.config;

import com.jy.adscm.core.interceptor.AdscmCoreInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;

/**
 * @author yyy
 * @ClassName AdscmWebConfig
 * @Description springMvc 相关配置
 * @date 2018/8/3 14:54
 */
@Configuration
public class AdscmWebConfig extends WebMvcConfigurerAdapter {

     @Value("${ly.upload.imagePath}")
     private  String imagePath;
     @Value("${wechat.upload}")
     private  String wechatPath;
    /**
     * 解决跨域问题
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
         * 说明：增加虚拟路径(经过本人测试：在此处配置的虚拟路径，用springboot内置的tomcat时有效，
         * 用外部的tomcat也有效;所以用到外部的tomcat时不需在tomcat/config下的相应文件配置虚拟路径了,阿里云linux也没问题)
         */
        //Windows下
        registry.addResourceHandler("/imagePath/**").addResourceLocations("file:"+imagePath);
        registry.addResourceHandler("/image/**").addResourceLocations("file:"+wechatPath);
        //Mac或Linux下(没有CDEF盘符)
        //registry.addResourceHandler("/uploads/**").addResourceLocations("file:/Users/liuyanzhao/Documents/uploads/");
        super.addResourceHandlers(registry);
    }

}
